<template>
  <div class="add-user-by-admin">
    <div class="box">
      <div class="head">
        <h3 class="title">新增用户</h3>
        <span class="close" @click="showAddUser">x</span>
      </div>
      <div class="input-box">
        <div class="username">
          <label for="username">用户名</label>
          <input type="text" id="username" v-model="username" />
        </div>
        <div class="password">
          <label for="password">密码</label>
          <input type="password" id="password" v-model="password" />
        </div>
        <div class="type">
          <label for="type">用户类型</label>
          <select id="type" v-model="type">
            <option value="admin">管理员</option>
            <option value="traffic">交管员</option>
            <option value="common">普通用户</option>
          </select>
        </div>
      </div>
      <div class="btn-box">
        <button @click="addUser({ username, password, type })">确定</button>
        <button @click="showAddUser">取消</button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { useMapgisStore_zxh } from '@/stores/mapgis-zxh.js'
import { storeToRefs } from 'pinia'
const { username, password, type } = storeToRefs(useMapgisStore_zxh())
const { showAddUser, addUser } = useMapgisStore_zxh()
</script>

<style scoped>
.box {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 400px;
  height: 300px;
  background-color: #fff;
  border-radius: 10px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
  z-index: 1001;
}
.head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 50px;
  padding: 0 20px;
  background-color: #f5f5f5;
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
}
.title {
  font-size: 20px;
  font-weight: bold;
  color: #333;
}
.close {
  font-size: 20px;
  font-weight: bold;
  color: #333;
  cursor: pointer;
}
.input-box {
  padding: 20px;
}
.username label {
  display: block;
  margin-bottom: 5px;
  font-size: 16px;
  color: #333;
}
.username input {
  width: 100%;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
  font-size: 16px;
}
.password label {
  display: block;
  margin-bottom: 5px;
  font-size: 16px;
  color: #333;
}
.password input {
  width: 100%;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
  font-size: 16px;
}
.type label {
  display: block;
  margin-bottom: 5px;
  font-size: 16px;
  color: #333;
}
.type select {
  width: 100%;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
  font-size: 16px;
}
.btn-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  background-color: #f5f5f5;
  border-bottom-left-radius: 10px;
  border-bottom-right-radius: 10px;
}
</style>
